<template>
  <view class="content">
    <view class="item right-arrow" v-for="item in list" :key="item.familyId" @click="showActionSheet(item,index)">
       {{item.name}}
       <text>{{item.relation}}</text>
       <text>{{item.phone}}</text> 
    </view>
    <view style="height:200rpx"/>
    <suspension-button  :icon="'plus'" @suspensionButtonClick="add" />

  </view>
</template>

<script>
import basicsList from "@/components/basics-list/basics-list.vue";
import suspensionButton from "@/components/suspension-button/suspension-button.vue";

export default {
  components: { basicsList,suspensionButton },
  data() {
    return {
      patientId: uni.getStorageSync("patientId"),
      list:[]
    };
  },
  onShareAppMessage() {
    return this.$util.returnShareObj();
  },
  onLoad() {
           this.doctorListFamily();

  },
   onPullDownRefresh() {
                    this.doctorListFamily();

  },
  methods: {
    refreshByBack(){
                  this.doctorListFamily();

    },
    doctorListFamily(){
      this.$api.doctorListFamily({patientId:this.patientId}).then(res=>{
      uni.stopPullDownRefresh();

        if(res.code==200){
          this.list=res.data
        }
      })
    },
    showActionSheet(item,index) {
      uni.showActionSheet({
        itemList:["拨打电话", "编辑资料",'删除亲友'],
        success: (res) => {
          if (res.tapIndex == 1) {
              this.goDetail(item,index)
          } else if (res.tapIndex == 2) {
            this.del(item,index)
          } else {
                                        uni.makePhoneCall({
								phoneNumber:item.phone,
							})
          }
        },
      });
    },
    goDetail(item){
       uni.setStorage({
          key: "familyDetail",
          data: item,
        success: () => {
          this.$util.goUrl('/pagesPatient/familyDetail/index?isDetail=1')
        },
      });
    },
    add(){
    uni.removeStorageSync("familyDetail");
          this.$util.goUrl('/pagesPatient/familyDetail/index')
    },
    del(item,index){
       uni.showModal({
        title: "提示",
        content: "确认删除？",
        success: (res1) => {
          if (res1.confirm) {
            this.$api.patientDelFamily({familyId:item.familyId}).then((res) => {
              if (res.code == 200) {
                this.$util.showSuccessToast("删除成功");
                this.list.splice(index,1)
              }
            });
          }
        },
      });
    }
  },
};
</script>
<style lang="scss" scoped>
.content {
  background: $back-grey-color;
  min-height: 100vh;
  .item {
  width: 100vw;
  box-sizing: border-box;
  background: #fff;
  border-bottom: 1rpx solid $default-border-color;
  padding: 40rpx;
  position: relative;

  text{
  color:$font-grey-color;
margin-left:40rpx;
  }
}
.item::before {
  content: "";
  height: 1rpx;
  width: 40rpx;
  position: absolute;
  left: 0;
  bottom: 0;
  background: #fff;
}
}
</style>
